Set path Laura: ONLY USE FOR LAURA

# base_path <- "//home.kt.ktzh.ch/B117T23$/Desktop/Riskktaking/Data"
base_path <- "/Users/laurabazzigher/Documents/GitHub/risk_wvs/data/dataset/Data_S3"

Library

library(tidyverse)
library(ggplot2)
library(specr)
library(specr)
library(readxl)
library(ggthemes)
library(cowplot)
library(dplyr)
library(knitr)
library(kableExtra)
library(Hmisc)
remotes::install_github("masurp/specr")

Load all data

# Combined GPS WVS
risktaking <- read.csv(file.path(base_path, "gps_wvs_combined.csv"), header=TRUE, as.is=TRUE)

# Umbenennen von 'isocode' zu 'COUNTRY' in risktaking
risktaking <- risktaking %>%
  rename(COUNTRY = isocode)

risktaking <- risktaking %>%
  select(-hardship_index, -worldmap, -source)

hardship_hs <- read.csv(file.path(base_path, "hardship_HS.csv"))
hardship_finance <- read.csv(file.path(base_path, "hardship_finance.csv"))
hardship_crime <- read.csv(file.path(base_path, "hardship_crime.csv"))
hardship_environment <- read.csv(file.path(base_path, "hardship_environment.csv"))

# Entfernen der nicht benötigten Spalten aus den Datensätzen vor dem Zusammenführen
hardship_hs <- hardship_hs %>%
  select(-country, -avg_risktaking)
hardship_finance <- hardship_finance %>%
  select(-country, -avg_risktaking)
hardship_crime <- hardship_crime %>%
  select(-country, -avg_risktaking)
hardship_environment <- hardship_environment %>%
  select(-country, -avg_risktaking)

# Zusammenführen der Datensätze
hardship_combined <- risktaking %>%
  left_join(hardship_hs, by = "COUNTRY") %>%
  left_join(hardship_finance, by = "COUNTRY") %>%
  left_join(hardship_crime, by = "COUNTRY") %>%
  left_join(hardship_environment, by = "COUNTRY")

# Überprüfung der Struktur des kombinierten Datensatzes
#str(hardship_combined)

Calculate correlation with risktaking

# Berechnung der Korrelation zwischen risktaking und den anderen Variablen
correlation_results <- cor(hardship_combined[, sapply(hardship_combined, is.numeric)], use = "complete.obs")

# Korrelationstabelle für risktaking extrahieren
risktaking_correlations <- correlation_results["risktaking", ]

# Konvertierung der Korrelationsergebnisse in ein formatiertes Datenframe
correlation_table <- data.frame(
  Variable = names(risktaking_correlations),
  Correlation = risktaking_correlations
)

# Entfernen der Korrelation von risktaking mit sich selbst
correlation_table <- correlation_table[correlation_table$Variable != "risktaking", ]

# Sortieren der Ergebnisse nach dem Betrag der Korrelation, absteigend
correlation_table <- correlation_table[order(-abs(correlation_table$Correlation)), ]

# Anzeigen der Tabelle
kable(correlation_table, caption = "Korrelationen zwischen risktaking und anderen Variablen") %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
Korrelationen zwischen risktaking und anderen Variablen
Variable Correlation
age age -0.2381263
e_exp_watersanithyg100k e_exp_watersanithyg100k 0.1305587
HS_original_infantmortality HS_original_infantmortality 0.1298944
hardship_Finance_index hardship_Finance_index 0.1255989
HS_original_lifeexpectancy HS_original_lifeexpectancy 0.1244475
gender gender -0.1201418
e_oth_safewater e_oth_safewater 0.1159199
f_original_gini f_original_gini 0.1127801
e_original_gini e_original_gini 0.1127801
hardship_HS hardship_HS 0.1122306
hardship_Crime_index hardship_Crime_index 0.1043428
e_exp_airdeath100k e_exp_airdeath100k 0.0982860
e_oth_drinkingwater e_oth_drinkingwater 0.0974426
HS_oth_cleancooking HS_oth_cleancooking 0.0967826
f_original_gdp f_original_gdp 0.0955940
c_bh_violextchildprot c_bh_violextchildprot 0.0936960
e_exp_watersanithyg e_exp_watersanithyg 0.0926370
e_ses_gini e_ses_gini 0.0912298
c_bh_childmalt c_bh_childmalt 0.0876729
HS_alc_tax_wine HS_alc_tax_wine 0.0867029
c_original_homiciderate c_original_homiciderate 0.0826330
c_bh_homicide c_bh_homicide 0.0814154
c_bh_elderabuse c_bh_elderabuse 0.0796172
HS_drg_treatment HS_drg_treatment 0.0779335
f_hs_oopexp10 f_hs_oopexp10 0.0754779
f_eco_cpi f_eco_cpi 0.0751496
c_oth_polstab c_oth_polstab 0.0744124
HS_sex_gini HS_sex_gini 0.0728827
f_eco_gdpdefl_linked f_eco_gdpdefl_linked 0.0726808
HS_alc_roaddeath HS_alc_roaddeath 0.0699059
c_bh_inthomicide c_bh_inthomicide 0.0649434
HS_nic_affordability HS_nic_affordability 0.0641391
c_theft_estcorruption c_theft_estcorruption 0.0559263
f_oth_insfinsvcs_int f_oth_insfinsvcs_int 0.0538295
HS_alc_agelim HS_alc_agelim -0.0533055
HS_original_genderequality HS_original_genderequality 0.0496918
HS_sex_antiretroviral HS_sex_antiretroviral 0.0495593
e_ses_school e_ses_school 0.0425655
c_bh_parviolenceprog c_bh_parviolenceprog 0.0421859
HS_oth_obesity HS_oth_obesity 0.0363355
HS_mh_mhhospit HS_mh_mhhospit 0.0209093
HS_mh_policy HS_mh_policy -0.0149841
f_inv_acctownership_primaryedu f_inv_acctownership_primaryedu 0.0114821
e_exp_disaster e_exp_disaster -0.0013405

Table with Correlation hardship factors and risktaking

# Laden notwendiger Bibliotheken
library(Hmisc)
library(kableExtra)

# Auswahl aller numerischen Variablen
numeric_vars <- hardship_combined %>%
  select(where(is.numeric))

# Berechnen der Korrelationsmatrix und der p-Werte
cor_results <- rcorr(as.matrix(numeric_vars))

# Korrelationen und p-Werte spezifisch für 'risktaking' extrahieren
correlations <- cor_results$r[, "risktaking"]  # Korrelationen zu 'risktaking'
p_values <- cor_results$P[, "risktaking"]      # p-Werte zu 'risktaking'

# Datenrahmen für die Darstellung erstellen
cor_table <- data.frame(
  Variable = rownames(cor_results$r),  # Namen der Variablen
  Correlation = round(correlations, 5),  # Korrelationswerte, gerundet auf 5 Dezimalstellen
  P_value = format(p_values, scientific = TRUE),  # p-Werte in wissenschaftlicher Notation
  Significant = ifelse(p_values < 0.05, "Yes", "No")  # Signifikanzflag, basierend auf p-Wert
)

# Tabellendarstellung mit 'kable' und 'kableExtra'
cor_table %>%
  kable("html", caption = "Correlations with Risktaking: Summary of Results") %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
  column_spec(2, bold = TRUE) %>%
  column_spec(3, background = "lightyellow")
Correlations with Risktaking: Summary of Results
Variable Correlation P_value Significant
gender gender -0.11984 0.000000e+00 Yes
age age -0.24184 0.000000e+00 Yes
risktaking risktaking 1.00000 NA NA
HS_alc_agelim HS_alc_agelim -0.05364 0.000000e+00 Yes
HS_alc_tax_wine HS_alc_tax_wine 0.08408 0.000000e+00 Yes
HS_alc_roaddeath HS_alc_roaddeath 0.07748 0.000000e+00 Yes
HS_drg_treatment HS_drg_treatment 0.07606 0.000000e+00 Yes
HS_nic_affordability HS_nic_affordability 0.07479 0.000000e+00 Yes
HS_mh_policy HS_mh_policy -0.00730 5.432256e-04 Yes
HS_sex_gini HS_sex_gini 0.08042 0.000000e+00 Yes
HS_oth_obesity HS_oth_obesity 0.01722 4.440892e-16 Yes
HS_oth_cleancooking HS_oth_cleancooking 0.10040 0.000000e+00 Yes
HS_mh_mhhospit HS_mh_mhhospit 0.03081 0.000000e+00 Yes
HS_sex_antiretroviral HS_sex_antiretroviral 0.05036 0.000000e+00 Yes
HS_original_infantmortality HS_original_infantmortality 0.14188 0.000000e+00 Yes
HS_original_lifeexpectancy HS_original_lifeexpectancy 0.13508 0.000000e+00 Yes
HS_original_genderequality HS_original_genderequality 0.05193 0.000000e+00 Yes
hardship_HS hardship_HS 0.11857 0.000000e+00 Yes
f_inv_acctownership_primaryedu f_inv_acctownership_primaryedu 0.02165 0.000000e+00 Yes
f_oth_insfinsvcs_int f_oth_insfinsvcs_int 0.05273 0.000000e+00 Yes
f_hs_oopexp10 f_hs_oopexp10 0.07968 0.000000e+00 Yes
f_eco_gdpdefl_linked f_eco_gdpdefl_linked 0.07069 0.000000e+00 Yes
f_eco_cpi f_eco_cpi 0.10108 0.000000e+00 Yes
f_original_gdp f_original_gdp 0.10264 0.000000e+00 Yes
f_original_gini f_original_gini 0.11561 0.000000e+00 Yes
hardship_Finance_index hardship_Finance_index 0.13907 0.000000e+00 Yes
c_bh_homicide c_bh_homicide 0.09742 0.000000e+00 Yes
c_bh_childmalt c_bh_childmalt 0.09575 0.000000e+00 Yes
c_bh_violextchildprot c_bh_violextchildprot 0.09740 0.000000e+00 Yes
c_bh_parviolenceprog c_bh_parviolenceprog 0.04102 0.000000e+00 Yes
c_bh_elderabuse c_bh_elderabuse 0.08784 0.000000e+00 Yes
c_bh_inthomicide c_bh_inthomicide 0.08021 0.000000e+00 Yes
c_theft_estcorruption c_theft_estcorruption 0.06759 0.000000e+00 Yes
c_oth_polstab c_oth_polstab 0.08484 0.000000e+00 Yes
c_original_homiciderate c_original_homiciderate 0.09861 0.000000e+00 Yes
hardship_Crime_index hardship_Crime_index 0.11775 0.000000e+00 Yes
e_original_gini e_original_gini 0.11728 0.000000e+00 Yes
e_oth_drinkingwater e_oth_drinkingwater 0.10202 0.000000e+00 Yes
e_oth_safewater e_oth_safewater 0.12215 0.000000e+00 Yes
e_exp_watersanithyg100k e_exp_watersanithyg100k 0.13797 0.000000e+00 Yes
e_ses_gini e_ses_gini 0.09593 0.000000e+00 Yes
e_ses_school e_ses_school 0.04516 0.000000e+00 Yes
e_exp_disaster e_exp_disaster -0.01658 3.996803e-15 Yes
e_exp_airdeath100k e_exp_airdeath100k 0.11031 0.000000e+00 Yes
e_exp_watersanithyg e_exp_watersanithyg 0.09126 0.000000e+00 Yes

Setup for specifications

library(specr)

# Setup für die Spezifikationen mit einer umfassenderen Auswahl von Variablen
specification <- setup(
  data = hardship_combined,
  y = "risktaking",  # abhängige Variable
  x = c("HS_alc_agelim", "HS_alc_tax_wine", "HS_alc_roaddeath", 
        "HS_drg_treatment", "HS_nic_affordability", "HS_mh_policy",
        "HS_sex_gini", "HS_oth_obesity", "HS_oth_cleancooking",
        "HS_mh_mhhospit", "HS_sex_antiretroviral", "HS_original_infantmortality",
        "HS_original_lifeexpectancy", "HS_original_genderequality",
        "hardship_HS", "f_inv_acctownership_primaryedu", "f_oth_insfinsvcs_int",
        "f_hs_oopexp10", "f_eco_gdpdefl_linked", "f_eco_cpi",
        "f_original_gdp", "f_original_gini", "hardship_Finance_index",
        "c_bh_homicide", "c_bh_childmalt", "c_bh_violextchildprot",
        "c_bh_parviolenceprog", "c_bh_elderabuse", "c_bh_inthomicide",
        "c_theft_estcorruption", "c_oth_polstab", "c_original_homiciderate",
        "hardship_Crime_index", "e_original_gini", "e_oth_drinkingwater",
        "e_oth_safewater", "e_exp_watersanithyg100k", "e_ses_gini",
        "e_ses_school", "e_exp_disaster", "e_exp_airdeath100k", 
        "e_exp_watersanithyg"),
  model = "lm"
)

# Zusammenfassung der Spezifikationen
summary(specification)
## Setup for the Specification Curve Analysis
## -------------------------------------------
## Class:                      specr.setup -- version: 1.0.1 
## Number of specifications:   42 
## 
## Specifications:
## 
##   Independent variable:     HS_alc_agelim, HS_alc_tax_wine, HS_alc_roaddeath, HS_drg_treatment, HS_nic_affordability, HS_mh_policy, HS_sex_gini, HS_oth_obesity, HS_oth_cleancooking, HS_mh_mhhospit, HS_sex_antiretroviral, HS_original_infantmortality, HS_original_lifeexpectancy, HS_original_genderequality, hardship_HS, f_inv_acctownership_primaryedu, f_oth_insfinsvcs_int, f_hs_oopexp10, f_eco_gdpdefl_linked, f_eco_cpi, f_original_gdp, f_original_gini, hardship_Finance_index, c_bh_homicide, c_bh_childmalt, c_bh_violextchildprot, c_bh_parviolenceprog, c_bh_elderabuse, c_bh_inthomicide, c_theft_estcorruption, c_oth_polstab, c_original_homiciderate, hardship_Crime_index, e_original_gini, e_oth_drinkingwater, e_oth_safewater, e_exp_watersanithyg100k, e_ses_gini, e_ses_school, e_exp_disaster, e_exp_airdeath100k, e_exp_watersanithyg 
##   Dependent variable:       risktaking 
##   Models:                   lm 
##   Covariates:               no covariates 
##   Subsets analyses:         all 
## 
## Function used to extract parameters:
## 
##   function (x) 
## broom::tidy(x, conf.int = TRUE)
## <environment: 0x1444b6940>
## 
## 
## Head of specifications table (first 6 rows):
## # A tibble: 6 × 6
##   x                    y          model controls      subsets formula           
##   <chr>                <chr>      <chr> <chr>         <chr>   <glue>            
## 1 HS_alc_agelim        risktaking lm    no covariates all     risktaking ~ HS_a…
## 2 HS_alc_tax_wine      risktaking lm    no covariates all     risktaking ~ HS_a…
## 3 HS_alc_roaddeath     risktaking lm    no covariates all     risktaking ~ HS_a…
## 4 HS_drg_treatment     risktaking lm    no covariates all     risktaking ~ HS_d…
## 5 HS_nic_affordability risktaking lm    no covariates all     risktaking ~ HS_n…
## 6 HS_mh_policy         risktaking lm    no covariates all     risktaking ~ HS_m…

run specifications

specification_results <- specr(specification)
specification_results
## Models fitted based on 42 specifications
## Number of cores used: 1 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min  max  q25  q75
##    0.91 0.33 -0.58 2.46 0.68 1.12
summary(specification_results, digits = 5)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    7.033 sec elapsed 
##   Number of specifications:       42 
## 
## Descriptive summary of the specification curve:
## 
##   median     mad      min     max     q25     q75
##  0.91313 0.32865 -0.57659 2.46013 0.67921 1.12087
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  224583 221536 225551
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 HS_alc_agel… risk… lm    no cova… all     riskta…   -0.577    0.0226    -25.5 
## 2 HS_alc_tax_… risk… lm    no cova… all     riskta…    0.917    0.0229     40.0 
## 3 HS_alc_road… risk… lm    no cova… all     riskta…    0.853    0.0232     36.8 
## 4 HS_drg_trea… risk… lm    no cova… all     riskta…    0.784    0.0217     36.1 
## 5 HS_nic_affo… risk… lm    no cova… all     riskta…    0.806    0.0227     35.5 
## 6 HS_mh_policy risk… lm    no cova… all     riskta…   -0.170    0.0491     -3.46
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

summarizing the parameter distribution

summary(specification_results, type = "curve")
## # A tibble: 1 × 7
##   median   mad    min   max   q25   q75    obs
##    <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>
## 1  0.913 0.329 -0.577  2.46 0.679  1.12 224583
summary(specification_results, 
        type = "curve", 
        group = "x",           
        stats = c("median", "mean", "min", "max"))  # Statistiken in einem Vektor auflisten
## # A tibble: 42 × 6
##    x                           median   mean    min    max    obs
##    <chr>                        <dbl>  <dbl>  <dbl>  <dbl>  <int>
##  1 HS_alc_agelim               -0.577 -0.577 -0.577 -0.577 224583
##  2 HS_alc_roaddeath             0.853  0.853  0.853  0.853 224583
##  3 HS_alc_tax_wine              0.917  0.917  0.917  0.917 224583
##  4 HS_drg_treatment             0.784  0.784  0.784  0.784 224583
##  5 HS_mh_mhhospit               0.327  0.327  0.327  0.327 224583
##  6 HS_mh_policy                -0.170 -0.170 -0.170 -0.170 224583
##  7 HS_nic_affordability         0.806  0.806  0.806  0.806 224583
##  8 HS_original_genderequality   0.677  0.677  0.677  0.677 224583
##  9 HS_original_infantmortality  1.49   1.49   1.49   1.49  224583
## 10 HS_original_lifeexpectancy   1.40   1.40   1.40   1.40  224583
## # ℹ 32 more rows

Plots

plot(specification_results)

(a <- plot(specification_results, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b <- plot(specification_results, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c <- plot(specification_results, type = "samplesizes") + ylim(0, 400))

plot_grid(a, b, c, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for males

specification_males <- setup(
  data = hardship_combined %>%
           filter(gender == 1),  # Filter for males
  y = "risktaking",
  x = c("HS_alc_agelim", "HS_alc_tax_wine", "HS_alc_roaddeath", 
        "HS_drg_treatment", "HS_nic_affordability", "HS_mh_policy",
        "HS_sex_gini", "HS_oth_obesity", "HS_oth_cleancooking",
        "HS_mh_mhhospit", "HS_sex_antiretroviral", "HS_original_infantmortality",
        "HS_original_lifeexpectancy", "HS_original_genderequality",
        "hardship_HS", "f_inv_acctownership_primaryedu", "f_oth_insfinsvcs_int",
        "f_hs_oopexp10", "f_eco_gdpdefl_linked", "f_eco_cpi",
        "f_original_gdp", "f_original_gini", "hardship_Finance_index",
        "c_bh_homicide", "c_bh_childmalt", "c_bh_violextchildprot",
        "c_bh_parviolenceprog", "c_bh_elderabuse", "c_bh_inthomicide",
        "c_theft_estcorruption", "c_oth_polstab", "c_original_homiciderate",
        "hardship_Crime_index", "e_original_gini", "e_oth_drinkingwater",
        "e_oth_safewater", "e_exp_watersanithyg100k", "e_ses_gini",
        "e_ses_school", "e_exp_disaster", "e_exp_airdeath100k", 
        "e_exp_watersanithyg"),
  model = "lm"
)

# Run the specifications for males
specification_results_males <- specr(specification_males)

# View the summary of the results
summary(specification_results_males)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    3.628 sec elapsed 
##   Number of specifications:       42 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min max  q25  q75
##       1 0.37 -0.64 2.8 0.76 1.23
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  119096 117485 119591
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 HS_alc_agel… risk… lm    no cova… all     riskta…    -0.64      0.03     -19.9
## 2 HS_alc_tax_… risk… lm    no cova… all     riskta…     0.93      0.03      29.5
## 3 HS_alc_road… risk… lm    no cova… all     riskta…     1         0.03      31.2
## 4 HS_drg_trea… risk… lm    no cova… all     riskta…     0.83      0.03      28.6
## 5 HS_nic_affo… risk… lm    no cova… all     riskta…     0.94      0.03      30.0
## 6 HS_mh_policy risk… lm    no cova… all     riskta…    -0.11      0.07      -1.7
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for male subset results

plot(specification_results_males)

(a_male <- plot(specification_results_males, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_male <- plot(specification_results_males, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_male <- plot(specification_results_males, type = "samplesizes") + ylim(0, 400))

plot_grid(a_male, b_male, c_male, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_males, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for females

specification_females <- setup(
  data = hardship_combined %>%
           filter(gender == 0),  # Filter for females
  y = "risktaking",
  x = c("HS_alc_agelim", "HS_alc_tax_wine", "HS_alc_roaddeath", 
        "HS_drg_treatment", "HS_nic_affordability", "HS_mh_policy",
        "HS_sex_gini", "HS_oth_obesity", "HS_oth_cleancooking",
        "HS_mh_mhhospit", "HS_sex_antiretroviral", "HS_original_infantmortality",
        "HS_original_lifeexpectancy", "HS_original_genderequality",
        "hardship_HS", "f_inv_acctownership_primaryedu", "f_oth_insfinsvcs_int",
        "f_hs_oopexp10", "f_eco_gdpdefl_linked", "f_eco_cpi",
        "f_original_gdp", "f_original_gini", "hardship_Finance_index",
        "c_bh_homicide", "c_bh_childmalt", "c_bh_violextchildprot",
        "c_bh_parviolenceprog", "c_bh_elderabuse", "c_bh_inthomicide",
        "c_theft_estcorruption", "c_oth_polstab", "c_original_homiciderate",
        "hardship_Crime_index", "e_original_gini", "e_oth_drinkingwater",
        "e_oth_safewater", "e_exp_watersanithyg100k", "e_ses_gini",
        "e_ses_school", "e_exp_disaster", "e_exp_airdeath100k", 
        "e_exp_watersanithyg"),
  model = "lm"
)

# Run the specifications for females
specification_results_females <- specr(specification_females)

# View the summary of the results
summary(specification_results_females)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    3.134 sec elapsed 
##   Number of specifications:       42 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min  max  q25  q75
##    0.76 0.29 -0.46 2.04 0.54 0.95
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  105487 104051 105960
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 HS_alc_agel… risk… lm    no cova… all     riskta…    -0.46      0.03    -14.6 
## 2 HS_alc_tax_… risk… lm    no cova… all     riskta…     0.84      0.03     25.4 
## 3 HS_alc_road… risk… lm    no cova… all     riskta…     0.69      0.03     20.9 
## 4 HS_drg_trea… risk… lm    no cova… all     riskta…     0.7       0.03     21.8 
## 5 HS_nic_affo… risk… lm    no cova… all     riskta…     0.61      0.03     18.9 
## 6 HS_mh_policy risk… lm    no cova… all     riskta…    -0.26      0.07     -3.72
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for female subset results

plot(specification_results_females)

(a_female <- plot(specification_results_females, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_female <- plot(specification_results_females, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_female <- plot(specification_results_females, type = "samplesizes") + ylim(0, 400))

plot_grid(a_female, b_female, c_female, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_females, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Hardship Health/Safety

Setup for specifications

library(specr)

# Setup für die Spezifikationen mit einer umfassenderen Auswahl von Variablen
specification <- setup(
  data = hardship_combined,
  y = "risktaking",  # abhängige Variable
  x = c("HS_alc_agelim", "HS_alc_tax_wine", "HS_alc_roaddeath", 
        "HS_drg_treatment", "HS_nic_affordability", "HS_mh_policy",
        "HS_sex_gini", "HS_oth_obesity", "HS_oth_cleancooking",
        "HS_mh_mhhospit", "HS_sex_antiretroviral", "HS_original_infantmortality",
        "HS_original_lifeexpectancy", "HS_original_genderequality",
        "hardship_HS"),
  model = "lm"
)

# Zusammenfassung der Spezifikationen
summary(specification)
## Setup for the Specification Curve Analysis
## -------------------------------------------
## Class:                      specr.setup -- version: 1.0.1 
## Number of specifications:   15 
## 
## Specifications:
## 
##   Independent variable:     HS_alc_agelim, HS_alc_tax_wine, HS_alc_roaddeath, HS_drg_treatment, HS_nic_affordability, HS_mh_policy, HS_sex_gini, HS_oth_obesity, HS_oth_cleancooking, HS_mh_mhhospit, HS_sex_antiretroviral, HS_original_infantmortality, HS_original_lifeexpectancy, HS_original_genderequality, hardship_HS 
##   Dependent variable:       risktaking 
##   Models:                   lm 
##   Covariates:               no covariates 
##   Subsets analyses:         all 
## 
## Function used to extract parameters:
## 
##   function (x) 
## broom::tidy(x, conf.int = TRUE)
## <environment: 0x1419ea940>
## 
## 
## Head of specifications table (first 6 rows):
## # A tibble: 6 × 6
##   x                    y          model controls      subsets formula           
##   <chr>                <chr>      <chr> <chr>         <chr>   <glue>            
## 1 HS_alc_agelim        risktaking lm    no covariates all     risktaking ~ HS_a…
## 2 HS_alc_tax_wine      risktaking lm    no covariates all     risktaking ~ HS_a…
## 3 HS_alc_roaddeath     risktaking lm    no covariates all     risktaking ~ HS_a…
## 4 HS_drg_treatment     risktaking lm    no covariates all     risktaking ~ HS_d…
## 5 HS_nic_affordability risktaking lm    no covariates all     risktaking ~ HS_n…
## 6 HS_mh_policy         risktaking lm    no covariates all     risktaking ~ HS_m…

run specifications

specification_results <- specr(specification)
specification_results
## Models fitted based on 15 specifications
## Number of cores used: 1 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min  max  q25 q75
##    0.81 0.43 -0.58 2.46 0.47   1
summary(specification_results, digits = 5)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    2.721 sec elapsed 
##   Number of specifications:       15 
## 
## Descriptive summary of the specification curve:
## 
##   median    mad      min     max     q25     q75
##  0.80569 0.4252 -0.57659 2.46013 0.47276 1.00453
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  224583 224583 224583
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 HS_alc_agel… risk… lm    no cova… all     riskta…   -0.577    0.0226    -25.5 
## 2 HS_alc_tax_… risk… lm    no cova… all     riskta…    0.917    0.0229     40.0 
## 3 HS_alc_road… risk… lm    no cova… all     riskta…    0.853    0.0232     36.8 
## 4 HS_drg_trea… risk… lm    no cova… all     riskta…    0.784    0.0217     36.1 
## 5 HS_nic_affo… risk… lm    no cova… all     riskta…    0.806    0.0227     35.5 
## 6 HS_mh_policy risk… lm    no cova… all     riskta…   -0.170    0.0491     -3.46
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

summarizing the parameter distribution

summary(specification_results, type = "curve")
## # A tibble: 1 × 7
##   median   mad    min   max   q25   q75    obs
##    <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>  <int>
## 1  0.806 0.425 -0.577  2.46 0.473  1.00 224583
summary(specification_results, 
        type = "curve", 
        group = "x",           
        stats = c("median", "mean", "min", "max"))  # Statistiken in einem Vektor auflisten
## # A tibble: 15 × 6
##    x                           median   mean    min    max    obs
##    <chr>                        <dbl>  <dbl>  <dbl>  <dbl>  <int>
##  1 HS_alc_agelim               -0.577 -0.577 -0.577 -0.577 224583
##  2 HS_alc_roaddeath             0.853  0.853  0.853  0.853 224583
##  3 HS_alc_tax_wine              0.917  0.917  0.917  0.917 224583
##  4 HS_drg_treatment             0.784  0.784  0.784  0.784 224583
##  5 HS_mh_mhhospit               0.327  0.327  0.327  0.327 224583
##  6 HS_mh_policy                -0.170 -0.170 -0.170 -0.170 224583
##  7 HS_nic_affordability         0.806  0.806  0.806  0.806 224583
##  8 HS_original_genderequality   0.677  0.677  0.677  0.677 224583
##  9 HS_original_infantmortality  1.49   1.49   1.49   1.49  224583
## 10 HS_original_lifeexpectancy   1.40   1.40   1.40   1.40  224583
## 11 HS_oth_cleancooking          1.09   1.09   1.09   1.09  224583
## 12 HS_oth_obesity               0.169  0.169  0.169  0.169 224583
## 13 HS_sex_antiretroviral        0.618  0.618  0.618  0.618 224583
## 14 HS_sex_gini                  0.837  0.837  0.837  0.837 224583
## 15 hardship_HS                  2.46   2.46   2.46   2.46  224583

Plots

plot(specification_results)

(a <- plot(specification_results, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b <- plot(specification_results, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c <- plot(specification_results, type = "samplesizes") + ylim(0, 400))

plot_grid(a, b, c, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2.5, 0.8),
          axis = "rbl")

plot(specification_results, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for males

specification_males <- setup(
  data = hardship_combined %>%
           filter(gender == 1),  # Filter for males
  y = "risktaking",
  x = c("HS_alc_agelim", "HS_alc_tax_wine", "HS_alc_roaddeath", 
        "HS_drg_treatment", "HS_nic_affordability", "HS_mh_policy",
        "HS_sex_gini", "HS_oth_obesity", "HS_oth_cleancooking",
        "HS_mh_mhhospit", "HS_sex_antiretroviral", "HS_original_infantmortality",
        "HS_original_lifeexpectancy", "HS_original_genderequality",
        "hardship_HS"),
  model = "lm"
)

# Run the specifications for males
specification_results_males <- specr(specification_males)

# View the summary of the results
summary(specification_results_males)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    1.341 sec elapsed 
##   Number of specifications:       15 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min max  q25  q75
##    0.93 0.53 -0.64 2.8 0.49 1.14
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  119096 119096 119096
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 HS_alc_agel… risk… lm    no cova… all     riskta…    -0.64      0.03     -19.9
## 2 HS_alc_tax_… risk… lm    no cova… all     riskta…     0.93      0.03      29.5
## 3 HS_alc_road… risk… lm    no cova… all     riskta…     1         0.03      31.2
## 4 HS_drg_trea… risk… lm    no cova… all     riskta…     0.83      0.03      28.6
## 5 HS_nic_affo… risk… lm    no cova… all     riskta…     0.94      0.03      30.0
## 6 HS_mh_policy risk… lm    no cova… all     riskta…    -0.11      0.07      -1.7
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for male subset results

plot(specification_results_males)

(a_male <- plot(specification_results_males, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_male <- plot(specification_results_males, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_male <- plot(specification_results_males, type = "samplesizes") + ylim(0, 400))

plot_grid(a_male, b_male, c_male, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_males, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for females

specification_females <- setup(
  data = hardship_combined %>%
           filter(gender == 0),  # Filter for females
  y = "risktaking",
  x = c("HS_alc_agelim", "HS_alc_tax_wine", "HS_alc_roaddeath", 
        "HS_drg_treatment", "HS_nic_affordability", "HS_mh_policy",
        "HS_sex_gini", "HS_oth_obesity", "HS_oth_cleancooking",
        "HS_mh_mhhospit", "HS_sex_antiretroviral", "HS_original_infantmortality",
        "HS_original_lifeexpectancy", "HS_original_genderequality",
        "hardship_HS"),
  model = "lm"
)

# Run the specifications for females
specification_results_females <- specr(specification_females)

# View the summary of the results
summary(specification_results_females)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    1.238 sec elapsed 
##   Number of specifications:       15 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min  max q25  q75
##    0.63 0.31 -0.46 1.96 0.4 0.83
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  105487 105487 105487
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 HS_alc_agel… risk… lm    no cova… all     riskta…    -0.46      0.03    -14.6 
## 2 HS_alc_tax_… risk… lm    no cova… all     riskta…     0.84      0.03     25.4 
## 3 HS_alc_road… risk… lm    no cova… all     riskta…     0.69      0.03     20.9 
## 4 HS_drg_trea… risk… lm    no cova… all     riskta…     0.7       0.03     21.8 
## 5 HS_nic_affo… risk… lm    no cova… all     riskta…     0.61      0.03     18.9 
## 6 HS_mh_policy risk… lm    no cova… all     riskta…    -0.26      0.07     -3.72
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for female subset results

plot(specification_results_females)

(a_female <- plot(specification_results_females, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_female <- plot(specification_results_females, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_female <- plot(specification_results_females, type = "samplesizes") + ylim(0, 400))

plot_grid(a_female, b_female, c_female, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_females, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Hardship Finance

Setup for specifications

library(specr)

# Setup für die Spezifikationen mit einer umfassenderen Auswahl von Variablen
specification <- setup(
  data = hardship_combined,
  y = "risktaking",  # abhängige Variable
  x = c("f_inv_acctownership_primaryedu", "f_oth_insfinsvcs_int",
        "f_hs_oopexp10", "f_eco_gdpdefl_linked", "f_eco_cpi",
        "f_original_gdp", "f_original_gini", "hardship_Finance_index"),
  model = "lm"
)

# Zusammenfassung der Spezifikationen
summary(specification)
## Setup for the Specification Curve Analysis
## -------------------------------------------
## Class:                      specr.setup -- version: 1.0.1 
## Number of specifications:   8 
## 
## Specifications:
## 
##   Independent variable:     f_inv_acctownership_primaryedu, f_oth_insfinsvcs_int, f_hs_oopexp10, f_eco_gdpdefl_linked, f_eco_cpi, f_original_gdp, f_original_gini, hardship_Finance_index 
##   Dependent variable:       risktaking 
##   Models:                   lm 
##   Covariates:               no covariates 
##   Subsets analyses:         all 
## 
## Function used to extract parameters:
## 
##   function (x) 
## broom::tidy(x, conf.int = TRUE)
## <environment: 0x14380f1c8>
## 
## 
## Head of specifications table (first 6 rows):
## # A tibble: 6 × 6
##   x                              y          model controls      subsets formula 
##   <chr>                          <chr>      <chr> <chr>         <chr>   <glue>  
## 1 f_inv_acctownership_primaryedu risktaking lm    no covariates all     risktak…
## 2 f_oth_insfinsvcs_int           risktaking lm    no covariates all     risktak…
## 3 f_hs_oopexp10                  risktaking lm    no covariates all     risktak…
## 4 f_eco_gdpdefl_linked           risktaking lm    no covariates all     risktak…
## 5 f_eco_cpi                      risktaking lm    no covariates all     risktak…
## 6 f_original_gdp                 risktaking lm    no covariates all     risktak…

run specifications

specification_results <- specr(specification)
specification_results
## Models fitted based on 8 specifications
## Number of cores used: 1 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad  min  max  q25  q75
##    0.88 0.37 0.22 2.43 0.66 1.12
summary(specification_results, digits = 5)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    1.441 sec elapsed 
##   Number of specifications:       8 
## 
## Descriptive summary of the specification curve:
## 
##   median     mad     min    max     q25     q75
##  0.87506 0.36897 0.22392 2.4322 0.66037 1.11566
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  225551 221536 225551
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 f_inv_accto… risk… lm    no cova… all     riskta…    0.224    0.0218      10.3
## 2 f_oth_insfi… risk… lm    no cova… all     riskta…    0.506    0.0202      25.1
## 3 f_hs_oopexp… risk… lm    no cova… all     riskta…    0.785    0.0207      38.0
## 4 f_eco_gdpde… risk… lm    no cova… all     riskta…    0.712    0.0213      33.4
## 5 f_eco_cpi    risk… lm    no cova… all     riskta…    0.965    0.02        48.3
## 6 f_original_… risk… lm    no cova… all     riskta…    1.14     0.0233      49.0
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

summarizing the parameter distribution

summary(specification_results, type = "curve")
## # A tibble: 1 × 7
##   median   mad   min   max   q25   q75    obs
##    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>
## 1  0.875 0.369 0.224  2.43 0.660  1.12 225551
summary(specification_results, 
        type = "curve", 
        group = "x",           
        stats = c("median", "mean", "min", "max"))  # Statistiken in einem Vektor auflisten
## # A tibble: 8 × 6
##   x                              median  mean   min   max    obs
##   <chr>                           <dbl> <dbl> <dbl> <dbl>  <int>
## 1 f_eco_cpi                       0.965 0.965 0.965 0.965 225551
## 2 f_eco_gdpdefl_linked            0.712 0.712 0.712 0.712 221536
## 3 f_hs_oopexp10                   0.785 0.785 0.785 0.785 225551
## 4 f_inv_acctownership_primaryedu  0.224 0.224 0.224 0.224 225551
## 5 f_original_gdp                  1.14  1.14  1.14  1.14  225551
## 6 f_original_gini                 1.11  1.11  1.11  1.11  225551
## 7 f_oth_insfinsvcs_int            0.506 0.506 0.506 0.506 225551
## 8 hardship_Finance_index          2.43  2.43  2.43  2.43  225551

Plots

plot(specification_results)

(a <- plot(specification_results, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b <- plot(specification_results, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c <- plot(specification_results, type = "samplesizes") + ylim(0, 400))

plot_grid(a, b, c, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for males

specification_males <- setup(
  data = hardship_combined %>%
           filter(gender == 1),  # Filter for males
  y = "risktaking",
  x = c("f_oth_insfinsvcs_int",
        "f_hs_oopexp10", "f_eco_gdpdefl_linked", "f_eco_cpi",
        "f_original_gdp", "f_original_gini", "hardship_Finance_index"
        ),
  model = "lm"
)

# Run the specifications for males
specification_results_males <- specr(specification_males)

# View the summary of the results
summary(specification_results_males)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    0.556 sec elapsed 
##   Number of specifications:       7 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad  min  max  q25  q75
##    1.05 0.37 0.61 2.73 0.85 1.24
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  119591 117485 119591
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 f_oth_insfi… risk… lm    no cova… all     riskta…     0.61      0.03      21.8
## 2 f_hs_oopexp… risk… lm    no cova… all     riskta…     0.89      0.03      31.6
## 3 f_eco_gdpde… risk… lm    no cova… all     riskta…     0.8       0.03      27.7
## 4 f_eco_cpi    risk… lm    no cova… all     riskta…     1.05      0.03      38.7
## 5 f_original_… risk… lm    no cova… all     riskta…     1.3       0.03      40.6
## 6 f_original_… risk… lm    no cova… all     riskta…     1.18      0.03      43.4
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for male subset results

plot(specification_results_males)

(a_male <- plot(specification_results_males, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_male <- plot(specification_results_males, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_male <- plot(specification_results_males, type = "samplesizes") + ylim(0, 400))

plot_grid(a_male, b_male, c_male, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_males, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for females

specification_females <- setup(
  data = hardship_combined %>%
           filter(gender == 0),  # Filter for females
  y = "risktaking",
  x = c("f_oth_insfinsvcs_int",
        "f_hs_oopexp10", "f_eco_gdpdefl_linked", "f_eco_cpi",
        "f_original_gdp", "f_original_gini", "hardship_Finance_index"
        ),
  model = "lm"
)

# Run the specifications for females
specification_results_females <- specr(specification_females)

# View the summary of the results
summary(specification_results_females)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    0.618 sec elapsed 
##   Number of specifications:       7 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad  min  max  q25  q75
##    0.86 0.32 0.38 2.04 0.63 0.94
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  105960 104051 105960
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 f_oth_insfi… risk… lm    no cova… all     riskta…     0.38      0.03      13.4
## 2 f_hs_oopexp… risk… lm    no cova… all     riskta…     0.64      0.03      21.6
## 3 f_eco_gdpde… risk… lm    no cova… all     riskta…     0.61      0.03      19.4
## 4 f_eco_cpi    risk… lm    no cova… all     riskta…     0.86      0.03      29.5
## 5 f_original_… risk… lm    no cova… all     riskta…     0.9       0.03      27.1
## 6 f_original_… risk… lm    no cova… all     riskta…     0.98      0.03      33.5
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for female subset results

plot(specification_results_females)

(a_female <- plot(specification_results_females, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_female <- plot(specification_results_females, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_female <- plot(specification_results_females, type = "samplesizes") + ylim(0, 400))

plot_grid(a_female, b_female, c_female, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_females, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Hardship Crime

Setup for specifications

library(specr)

# Setup für die Spezifikationen mit einer umfassenderen Auswahl von Variablen
specification <- setup(
  data = hardship_combined,
  y = "risktaking",  # abhängige Variable
  x = c("c_bh_homicide", "c_bh_childmalt", "c_bh_violextchildprot",
        "c_bh_parviolenceprog", "c_bh_elderabuse", "c_bh_inthomicide",
        "c_theft_estcorruption", "c_oth_polstab", "c_original_homiciderate",
        "hardship_Crime_index"),
  model = "lm"
)

# Zusammenfassung der Spezifikationen
summary(specification)
## Setup for the Specification Curve Analysis
## -------------------------------------------
## Class:                      specr.setup -- version: 1.0.1 
## Number of specifications:   10 
## 
## Specifications:
## 
##   Independent variable:     c_bh_homicide, c_bh_childmalt, c_bh_violextchildprot, c_bh_parviolenceprog, c_bh_elderabuse, c_bh_inthomicide, c_theft_estcorruption, c_oth_polstab, c_original_homiciderate, hardship_Crime_index 
##   Dependent variable:       risktaking 
##   Models:                   lm 
##   Covariates:               no covariates 
##   Subsets analyses:         all 
## 
## Function used to extract parameters:
## 
##   function (x) 
## broom::tidy(x, conf.int = TRUE)
## <environment: 0x1442cfc10>
## 
## 
## Head of specifications table (first 6 rows):
## # A tibble: 6 × 6
##   x                     y          model controls      subsets formula          
##   <chr>                 <chr>      <chr> <chr>         <chr>   <glue>           
## 1 c_bh_homicide         risktaking lm    no covariates all     risktaking ~ c_b…
## 2 c_bh_childmalt        risktaking lm    no covariates all     risktaking ~ c_b…
## 3 c_bh_violextchildprot risktaking lm    no covariates all     risktaking ~ c_b…
## 4 c_bh_parviolenceprog  risktaking lm    no covariates all     risktaking ~ c_b…
## 5 c_bh_elderabuse       risktaking lm    no covariates all     risktaking ~ c_b…
## 6 c_bh_inthomicide      risktaking lm    no covariates all     risktaking ~ c_b…

run specifications

specification_results <- specr(specification)
specification_results
## Models fitted based on 10 specifications
## Number of cores used: 1 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad  min  max  q25 q75
##    0.94 0.13 0.43 1.73 0.81   1
summary(specification_results, digits = 5)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    1.59 sec elapsed 
##   Number of specifications:       10 
## 
## Descriptive summary of the specification curve:
## 
##   median     mad     min     max     q25     q75
##  0.94298 0.13212 0.43309 1.73386 0.80953 0.99773
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  225551 225551 225551
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 c_bh_homici… risk… lm    no cova… all     riskta…    0.947    0.0204      46.5
## 2 c_bh_childm… risk… lm    no cova… all     riskta…    1.01     0.0221      45.7
## 3 c_bh_violex… risk… lm    no cova… all     riskta…    1.05     0.0227      46.5
## 4 c_bh_parvio… risk… lm    no cova… all     riskta…    0.433    0.0222      19.5
## 5 c_bh_eldera… risk… lm    no cova… all     riskta…    0.939    0.0224      41.9
## 6 c_bh_inthom… risk… lm    no cova… all     riskta…    0.780    0.0204      38.2
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

summarizing the parameter distribution

summary(specification_results, type = "curve")
## # A tibble: 1 × 7
##   median   mad   min   max   q25   q75    obs
##    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>
## 1  0.943 0.132 0.433  1.73 0.810 0.998 225551
summary(specification_results, 
        type = "curve", 
        group = "x",           
        stats = c("median", "mean", "min", "max"))  # Statistiken in einem Vektor auflisten
## # A tibble: 10 × 6
##    x                       median  mean   min   max    obs
##    <chr>                    <dbl> <dbl> <dbl> <dbl>  <int>
##  1 c_bh_childmalt           1.01  1.01  1.01  1.01  225551
##  2 c_bh_elderabuse          0.939 0.939 0.939 0.939 225551
##  3 c_bh_homicide            0.947 0.947 0.947 0.947 225551
##  4 c_bh_inthomicide         0.780 0.780 0.780 0.780 225551
##  5 c_bh_parviolenceprog     0.433 0.433 0.433 0.433 225551
##  6 c_bh_violextchildprot    1.05  1.05  1.05  1.05  225551
##  7 c_original_homiciderate  0.958 0.958 0.958 0.958 225551
##  8 c_oth_polstab            0.897 0.897 0.897 0.897 225551
##  9 c_theft_estcorruption    0.685 0.685 0.685 0.685 225551
## 10 hardship_Crime_index     1.73  1.73  1.73  1.73  225551

Plots

plot(specification_results)

(a <- plot(specification_results, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b <- plot(specification_results, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c <- plot(specification_results, type = "samplesizes") + ylim(0, 400))

plot_grid(a, b, c, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for males

specification_males <- setup(
  data = hardship_combined %>%
           filter(gender == 1),  # Filter for males
  y = "risktaking",
  x = c("c_bh_homicide", "c_bh_childmalt", "c_bh_violextchildprot",
        "c_bh_parviolenceprog", "c_bh_elderabuse", "c_bh_inthomicide",
        "c_theft_estcorruption", "c_oth_polstab", "c_original_homiciderate",
        "hardship_Crime_index"),
  model = "lm"
)

# Run the specifications for males
specification_results_males <- specr(specification_males)

# View the summary of the results
summary(specification_results_males)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    0.787 sec elapsed 
##   Number of specifications:       10 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad min  max  q25  q75
##    1.01 0.12 0.4 1.87 0.88 1.04
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  119591 119591 119591
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 c_bh_homici… risk… lm    no cova… all     riskta…     1.03      0.03      37.4
## 2 c_bh_childm… risk… lm    no cova… all     riskta…     1.04      0.03      34.4
## 3 c_bh_violex… risk… lm    no cova… all     riskta…     1.14      0.03      36.6
## 4 c_bh_parvio… risk… lm    no cova… all     riskta…     0.4       0.03      13.4
## 5 c_bh_eldera… risk… lm    no cova… all     riskta…     0.98      0.03      32.2
## 6 c_bh_inthom… risk… lm    no cova… all     riskta…     0.85      0.03      30.8
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for male subset results

plot(specification_results_males)

(a_male <- plot(specification_results_males, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_male <- plot(specification_results_males, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_male <- plot(specification_results_males, type = "samplesizes") + ylim(0, 400))

plot_grid(a_male, b_male, c_male, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_males, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for females

specification_females <- setup(
  data = hardship_combined %>%
           filter(gender == 0),  # Filter for females
  y = "risktaking",
  x = c("c_bh_homicide", "c_bh_childmalt", "c_bh_violextchildprot",
        "c_bh_parviolenceprog", "c_bh_elderabuse", "c_bh_inthomicide",
        "c_theft_estcorruption", "c_oth_polstab", "c_original_homiciderate",
        "hardship_Crime_index"),
  model = "lm"
)

# Run the specifications for females
specification_results_females <- specr(specification_females)

# View the summary of the results
summary(specification_results_females)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    0.782 sec elapsed 
##   Number of specifications:       10 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad  min  max  q25  q75
##    0.85 0.16 0.42 1.54 0.71 0.91
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  105960 105960 105960
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 c_bh_homici… risk… lm    no cova… all     riskta…     0.85      0.03      28.5
## 2 c_bh_childm… risk… lm    no cova… all     riskta…     0.93      0.03      29.1
## 3 c_bh_violex… risk… lm    no cova… all     riskta…     0.92      0.03      28.4
## 4 c_bh_parvio… risk… lm    no cova… all     riskta…     0.42      0.03      13.0
## 5 c_bh_eldera… risk… lm    no cova… all     riskta…     0.89      0.03      27.2
## 6 c_bh_inthom… risk… lm    no cova… all     riskta…     0.7       0.03      23.5
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for female subset results

plot(specification_results_females)

(a_female <- plot(specification_results_females, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_female <- plot(specification_results_females, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_female <- plot(specification_results_females, type = "samplesizes") + ylim(0, 400))

plot_grid(a_female, b_female, c_female, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_females, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Hardship Environment

Setup for specifications

library(specr)

# Setup für die Spezifikationen mit einer umfassenderen Auswahl von Variablen
specification <- setup(
  data = hardship_combined,
  y = "risktaking",  # abhängige Variable
  x = c("e_original_gini", "e_oth_drinkingwater",
        "e_oth_safewater", "e_exp_watersanithyg100k", "e_ses_gini",
        "e_ses_school", "e_exp_disaster", "e_exp_airdeath100k", 
        "e_exp_watersanithyg"),
  model = "lm"
)

# Zusammenfassung der Spezifikationen
summary(specification)
## Setup for the Specification Curve Analysis
## -------------------------------------------
## Class:                      specr.setup -- version: 1.0.1 
## Number of specifications:   9 
## 
## Specifications:
## 
##   Independent variable:     e_original_gini, e_oth_drinkingwater, e_oth_safewater, e_exp_watersanithyg100k, e_ses_gini, e_ses_school, e_exp_disaster, e_exp_airdeath100k, e_exp_watersanithyg 
##   Dependent variable:       risktaking 
##   Models:                   lm 
##   Covariates:               no covariates 
##   Subsets analyses:         all 
## 
## Function used to extract parameters:
## 
##   function (x) 
## broom::tidy(x, conf.int = TRUE)
## <environment: 0x1336a9d50>
## 
## 
## Head of specifications table (first 6 rows):
## # A tibble: 6 × 6
##   x                       y          model controls      subsets formula        
##   <chr>                   <chr>      <chr> <chr>         <chr>   <glue>         
## 1 e_original_gini         risktaking lm    no covariates all     risktaking ~ e…
## 2 e_oth_drinkingwater     risktaking lm    no covariates all     risktaking ~ e…
## 3 e_oth_safewater         risktaking lm    no covariates all     risktaking ~ e…
## 4 e_exp_watersanithyg100k risktaking lm    no covariates all     risktaking ~ e…
## 5 e_ses_gini              risktaking lm    no covariates all     risktaking ~ e…
## 6 e_ses_school            risktaking lm    no covariates all     risktaking ~ e…

run specifications

specification_results <- specr(specification)
specification_results
## Models fitted based on 9 specifications
## Number of cores used: 1 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min  max  q25  q75
##    1.13 0.32 -0.18 1.49 0.91 1.23
summary(specification_results, digits = 5)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    1.367 sec elapsed 
##   Number of specifications:       9 
## 
## Descriptive summary of the specification curve:
## 
##   median     mad      min    max     q25     q75
##  1.12536 0.31975 -0.17943 1.4903 0.90969 1.22758
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  224550 224550 224550
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 e_original_… risk… lm    no cova… all     riskta…    1.13     0.0201      56.0
## 2 e_oth_drink… risk… lm    no cova… all     riskta…    1.23     0.0253      48.6
## 3 e_oth_safew… risk… lm    no cova… all     riskta…    1.43     0.0244      58.3
## 4 e_exp_water… risk… lm    no cova… all     riskta…    1.49     0.0226      66.0
## 5 e_ses_gini   risk… lm    no cova… all     riskta…    0.947    0.0207      45.7
## 6 e_ses_school risk… lm    no cova… all     riskta…    0.580    0.0271      21.4
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

summarizing the parameter distribution

summary(specification_results, type = "curve")
## # A tibble: 1 × 7
##   median   mad    min   max   q25   q75    obs
##    <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>  <int>
## 1   1.13 0.320 -0.179  1.49 0.910  1.23 224550
summary(specification_results, 
        type = "curve", 
        group = "x",           
        stats = c("median", "mean", "min", "max"))  # Statistiken in einem Vektor auflisten
## # A tibble: 9 × 6
##   x                       median   mean    min    max    obs
##   <chr>                    <dbl>  <dbl>  <dbl>  <dbl>  <int>
## 1 e_exp_airdeath100k       1.13   1.13   1.13   1.13  224550
## 2 e_exp_disaster          -0.179 -0.179 -0.179 -0.179 224550
## 3 e_exp_watersanithyg      0.910  0.910  0.910  0.910 224550
## 4 e_exp_watersanithyg100k  1.49   1.49   1.49   1.49  224550
## 5 e_original_gini          1.13   1.13   1.13   1.13  224550
## 6 e_oth_drinkingwater      1.23   1.23   1.23   1.23  224550
## 7 e_oth_safewater          1.43   1.43   1.43   1.43  224550
## 8 e_ses_gini               0.947  0.947  0.947  0.947 224550
## 9 e_ses_school             0.580  0.580  0.580  0.580 224550

Plots

plot(specification_results)

(a <- plot(specification_results, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b <- plot(specification_results, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c <- plot(specification_results, type = "samplesizes") + ylim(0, 400))

plot_grid(a, b, c, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for males

specification_males <- setup(
  data = hardship_combined %>%
           filter(gender == 1),  # Filter for males
  y = "risktaking",
  x = c("e_original_gini", "e_oth_drinkingwater",
        "e_oth_safewater", "e_exp_watersanithyg100k", "e_ses_gini",
        "e_ses_school", "e_exp_disaster", "e_exp_airdeath100k", 
        "e_exp_watersanithyg"),
  model = "lm"
)

# Run the specifications for males
specification_results_males <- specr(specification_males)

# View the summary of the results
summary(specification_results_males)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    0.725 sec elapsed 
##   Number of specifications:       9 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min  max  q25  q75
##     1.2 0.32 -0.12 1.64 1.05 1.41
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  119093 119093 119093
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 e_original_… risk… lm    no cova… all     riskta…     1.2       0.03      43.8
## 2 e_oth_drink… risk… lm    no cova… all     riskta…     1.41      0.04      39.8
## 3 e_oth_safew… risk… lm    no cova… all     riskta…     1.62      0.03      47.9
## 4 e_exp_water… risk… lm    no cova… all     riskta…     1.64      0.03      52.9
## 5 e_ses_gini   risk… lm    no cova… all     riskta…     1.05      0.03      37.3
## 6 e_ses_school risk… lm    no cova… all     riskta…     0.66      0.04      17.5
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for male subset results

plot(specification_results_males)

(a_male <- plot(specification_results_males, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_male <- plot(specification_results_males, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_male <- plot(specification_results_males, type = "samplesizes") + ylim(0, 400))

plot_grid(a_male, b_male, c_male, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_males, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")

Subsetting data for females

specification_females <- setup(
  data = hardship_combined %>%
           filter(gender == 0),  # Filter for females
  y = "risktaking",
  x = c("e_original_gini", "e_oth_drinkingwater",
        "e_oth_safewater", "e_exp_watersanithyg100k", "e_ses_gini",
        "e_ses_school", "e_exp_disaster", "e_exp_airdeath100k", 
        "e_exp_watersanithyg"),
  model = "lm"
)

# Run the specifications for females
specification_results_females <- specr(specification_females)

# View the summary of the results
summary(specification_results_females)
## Results of the specification curve analysis
## -------------------
## Technical details:
## 
##   Class:                          specr.object -- version: 1.0.1 
##   Cores used:                     1 
##   Duration of fitting process:    0.717 sec elapsed 
##   Number of specifications:       9 
## 
## Descriptive summary of the specification curve:
## 
##  median  mad   min  max  q25 q75
##    0.96 0.27 -0.22 1.24 0.67   1
## 
## Descriptive summary of sample sizes: 
## 
##  median    min    max
##  105457 105457 105457
## 
## Head of the specification results (first 6 rows): 
## 
## # A tibble: 6 × 24
##   x            y     model controls subsets formula estimate std.error statistic
##   <chr>        <chr> <chr> <chr>    <chr>   <glue>     <dbl>     <dbl>     <dbl>
## 1 e_original_… risk… lm    no cova… all     riskta…     1         0.03      34.1
## 2 e_oth_drink… risk… lm    no cova… all     riskta…     0.96      0.04      27.0
## 3 e_oth_safew… risk… lm    no cova… all     riskta…     1.14      0.03      32.7
## 4 e_exp_water… risk… lm    no cova… all     riskta…     1.24      0.03      37.9
## 5 e_ses_gini   risk… lm    no cova… all     riskta…     0.8       0.03      26.4
## 6 e_ses_school risk… lm    no cova… all     riskta…     0.45      0.04      11.9
## # ℹ 15 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
## #   fit_r.squared <dbl>, fit_adj.r.squared <dbl>, fit_sigma <dbl>,
## #   fit_statistic <dbl>, fit_p.value <dbl>, fit_df <dbl>, fit_logLik <dbl>,
## #   fit_AIC <dbl>, fit_BIC <dbl>, fit_deviance <dbl>, fit_df.residual <dbl>,
## #   fit_nobs <dbl>

Plots for female subset results

plot(specification_results_females)

(a_female <- plot(specification_results_females, type = "curve", ci = F, ribbon = T) + 
   geom_point(size = 4))

(b_female <- plot(specification_results_females, type = "choices", choices = c("x", "y", "model", "controls")) +
   geom_point(size = 2, shape = 4)) 

(c_female <- plot(specification_results_females, type = "samplesizes") + ylim(0, 400))

plot_grid(a_female, b_female, c_female, ncol = 1,
          align = "v",
          rel_heights = c(1.5, 2, 0.8),
          axis = "rbl")

plot(specification_results_females, type = "boxplot") + 
  geom_point(alpha = .4) + 
  scale_fill_brewer(palette = "Pastel2") +
  labs(x = "Effect size", fill = "")